package com.sparkseries.controller;

import com.sparkseries.domain.vo.SysUserVO;
import com.sparkseries.dto.SysUserAuthenticationDTO;
import com.sparkseries.dto.SysUserDTO;
import com.sparkseries.service.SysUserService;
import com.sparkseries.common.util.domain.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户管理
 * TODO 参数校验 权限分配
 */
@RestController
@RequestMapping("user")
@Tag(name = "用户管理")
public class SysUserController {
    @Resource
    private SysUserService userService;

    /**
     * 用户注册
     * @param userDTO 用户传输类
     * @return 默认响应类
     */
    @PostMapping("register")
    @Operation(summary = "用户注册")
    @PreAuthorize("")
    public Result<?> register(@RequestBody SysUserDTO userDTO) {
        return userService.register(userDTO);
    }

    /**
     * 实名认证
     * @param authenticationDTO 实名信息传输类
     * @return 默认响应类
     */
    @PostMapping("userAuthenticate")
    @Operation(summary = "实名认证")
    @PreAuthorize("")
    public Result<?> userAuthenticate(@RequestBody SysUserAuthenticationDTO authenticationDTO) {
        return userService.userAuthenticate(authenticationDTO);
    }

    /**
     * 注销用户
     * @param userId 用户ID
     * @return 默认响应类
     */
    @DeleteMapping("deleteUser/{userId}")
    @Operation(summary = "注销用户")
    @PreAuthorize("")
    public Result<?> deleteUser(@PathVariable("userId") Long userId) {
        return userService.deleteUser(userId);
    }

    /**
     * 修改用户信息
     * @param userDTO 用户传输类
     * @return 默认响应类
     */
    @PutMapping("updateUserInfo")
    @Operation(summary = "修改用户信息")
    @PreAuthorize("")
    public Result<?> updateUserInfo(@RequestBody SysUserDTO userDTO) {
        return userService.updateUser(userDTO);
    }

    /**
     * 修改用户密码
     * @param userId 用户ID
     * @param password 用户密码
     * @return 默认响应类
     */
    @PutMapping("updateUserPassword/{userId}")
    @Operation(summary = "修改用户密码")
    @Parameter(name = "password", required = true)
    @PreAuthorize("")
    public Result<?> updateUserPassword(@PathVariable("userId") Long userId, @RequestParam("password") String password) {
        return userService.updateUserPassword(userId, password);
    }

    /**
     * 修改用户状态
     * @param userId 用户ID
     * @param status 是否启用（0-禁用，1-启用）
     * @return 默认响应类
     */
    @PutMapping("updateUserStatus/{userId}")
    @Operation(summary = "修改用户状态")
    @Parameter(name = "status", required = true)
    @PreAuthorize("")
    public Result<?> updateUserStatus(@PathVariable("userId") Long userId, @RequestParam("status") Integer status) {
        return userService.updateUserStatus(userId, status);
    }

    /**
     * 获取用户列表
     * @param userDTO 用户传输类
     * @return 用户响应类集合
     */
    @GetMapping("listUser")
    @Operation(summary = "获取用户列表")
    @PreAuthorize("")
    public Result<List<SysUserVO>> listUser(@RequestBody SysUserDTO userDTO) {
        return userService.listUser(userDTO);
    }

    /**
     * 获取用户信息
     * @param userId 用户ID
     * @return 用户响应类
     */
    @GetMapping("getUserInfo/{userId}")
    @Operation(summary = "获取用户信息")
    @PreAuthorize("")
    public Result<SysUserVO> getUserInfo(@PathVariable("userId") Long userId) {
        return userService.getUserInfo(userId);
    }

    /**
     * 密码强度检测
     * @param password 用户密码
     * @return 默认响应类
     */
    @GetMapping("detectPasswordSecurity")
    @Operation(summary = "密码强度检测")
    @PreAuthorize("")
    public Result<?> detectPasswordSecurity(@RequestParam("password") String password) {
        return userService.detectPasswordSecurity(password);
    }

    /**
     * 获取所有通知类型
     * @return 所有通知类型
     */
    @GetMapping("getAllNotifType")
    @Operation(summary = "获取所有通知类型")
    @PreAuthorize("")
    Result<?> getAllNotifType() {
        return userService.getAllNotifType();
    }
}
